<%@page import="java.util.*" %>

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<% String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="css/backstyle.css" rel="stylesheet" type="text/css"/>

    <script type="text/javascript" src="js/jquery-1.8.2.js"></script>

    <script type="text/javascript">
        $(function () {

            $("#selectIdFlag").change(function () { // 作用域不同
                // 获取表头单选框的状态
                var status = $(this).prop("checked");
                // 获取tboady中的单选框
                $(".userIdChebox").each(function () {
                    $(this).prop("checked", status);
                });
            });

            $("#batchDel").click(function () {
                var array = new Array();
                $(".userIdChebox:checked").each(function () {
                    array.push($(this).val());
                });

                $.ajax({
                    url: "UserController/batchDel",
                    type: "POST",
                    data: JSON.stringify(array), // 前端传递的数据使用JSON格式
                    contentType: "application/json",
                    success: function (data) {
                        if (data.code == 200) {
                            // location.reload(); // 刷新整个页面(再查一遍)
                            location.href= "UserController/userPage";
                        }
                    },
                    dataType: "JSON"
                });
            });
        })
    </script>
</head>

<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">数据表</a></li>
        <li><a href="#">基本内容</a></li>
    </ul>
</div>

<div class="rightinfo">

    <div class="tools">

        <ul class="toolbar">
            <li class="click">
                <span><img src="images/t01.png"/></span>
                <a href="back/user/adduser.jsp">添加
                </a>
            </li>

            <li id="batchDel">
                <span><img src="images/t03.png"/></span>
                <span>删除</span>
            </li>
        </ul>

    </div>
    <table class="tablelist">
        <thead>
        <tr>
            <th><input name="" id="selectIdFlag" type="checkbox" value=""/></th>
            <th>编号</th>
            <th>用户名</th>
            <th>性别</th>
            <th>邮箱</th>
            <th>年龄</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${requestScope.page.data}" var="user">
            <tr>
                <td><input class="userIdChebox" type="checkbox" value="${user.id}"/></td>
                <td>${user.id}</td>
                <td>${user.username}</td>
                <td>${user.sex==1?"男":"女"}</td>
                <td>${user.email}</td>
                <td>${user.age}</td>
                <td>
                    <a href="UserController/getUserById?id=${user.id}">编辑</a>
                    <a href="UserController/removeUserById?id=${user.id}">删除</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <!-- 包含分页导航条过来 -->
    <jsp:include page="/back/commons/page.jsp"></jsp:include>

    <div class="tip">
        <div class="tiptop"><span>提示信息</span><a></a></div>

        <div class="tipinfo">
            <span><img src="images/ticon.png"/></span>
            <div class="tipright">
                <p>是否确认对信息的修改 ？</p>
                <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
            </div>
        </div>

        <div class="tipbtn">
            <input name="" type="button" class="sure" value="确定"/>&nbsp;
            <input name="" type="button" class="cancel" value="取消"/>
        </div>

    </div>
</div>

<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
